package com.huawei.user.controller;
import com.huawei.common.PageView;
import com.huawei.user.vo.ThirdProcessDefinitionVO;
import com.huawei.user.vo.WorkFlowVO;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping(value = {"/deployment"})
public class ActController {
    /**
     * 查询工作流
     */
    @Autowired
    private RepositoryService repositoryService;
    @RequestMapping(value = "/list", method = {RequestMethod.POST, RequestMethod.GET})
    public PageView<List<ThirdProcessDefinitionVO>> selectPageProcessDefinition(@RequestBody WorkFlowVO workFlowVO) {
        PageView<List<ThirdProcessDefinitionVO>> pageView=new PageView<>();
        List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().listPage(0,10);
        Long defCount=repositoryService.createProcessDefinitionQuery().count();
        List<ThirdProcessDefinitionVO> thirdProcessDefinitionVOS=new ArrayList<>();
        list.forEach(item->{
            ThirdProcessDefinitionVO thirdProcessDefinitionVO=new ThirdProcessDefinitionVO();
            thirdProcessDefinitionVO.setId(item.getId());
            thirdProcessDefinitionVO.setDeploymentId(item.getDeploymentId());
            thirdProcessDefinitionVO.setDescription(item.getDescription());
            thirdProcessDefinitionVO.setDiagramResourceName(item.getDiagramResourceName());
            thirdProcessDefinitionVO.setKey(item.getKey());
            thirdProcessDefinitionVO.setName(item.getName());
            thirdProcessDefinitionVO.setResourceName(item.getResourceName());
            thirdProcessDefinitionVOS.add(thirdProcessDefinitionVO);
        });
        pageView.setRows(thirdProcessDefinitionVOS);
        pageView.setTotal(defCount.intValue());
        return pageView;
    }
}
